﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;

namespace PH_Zu_DataUpload_Auto.Properties
{
    internal class MesHttp
    {
        public async Task<HttpResponseMessage> upload(params string[] param)
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
            client.DefaultRequestHeaders.Add("ContentType", "application/json;");
            client.DefaultRequestHeaders.Add("ContentLength", "278");
            client.DefaultRequestHeaders.Add("Accept", "*/*");

            string json = "{\"SITE\":\""+param[0]+"\",   \"DC_USER\":\""+param[1]+"\",   \"RESOURCE_NO\":\""+param[2]+"\",   \"OPERATION_NO\":\""+param[3]+"\",   \"TS\":\""+param[4]+"\",   \"SHOP_ORDER_NO\":\""+param[5]+"\",   \"IS_FIRST_INSPECTION\":\""+param[6]+"\",   \"SFC_NO\":\""+param[7]+"\",   \"DC_TIME\":\""+param[8]+"\",   \"SHIFTS\":\""+param[9]+"\",   \"DC_RESULT\":\""+param[10]+"\",   \"PARAM_01\":\""+param[11]+"\",   \"PARAM_02\":\""+param[12]+"\",   \"PARAM_03\":\""+param[13]+"\",   \"PARAM_04\":\""+param[14]+"\",   \"PARAM_05\":\""+param[15]+"\",   \"PARAM_06\":\""+param[16]+"\",   \"PARAM_07\":\""+param[17]+"\",   \"PARAM_08\":\""+param[18]+"\",   \"PARAM_09\":\""+param[19]+"\",   \"PARAM_10\":\""+param[20]+"\",    \"PARAM_11\":\""+param[21]+"\",    \"PARAM_12\":\""+param[22]+"\"}";

            HttpContent content = new StringContent(json);
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            //提交参数设置
            HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["UploadUrl"].ToString(), content);
            return response;
        }

        public async Task<HttpResponseMessage> login(String username, String password)
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
            client.DefaultRequestHeaders.Add("ContentType", "application/json");
            client.DefaultRequestHeaders.Add("ContentLength", "95");
            client.DefaultRequestHeaders.Add("Cookie", "JSESSIONID=7DCA0E7D6482817672476CD633D6F2C9");
            client.DefaultRequestHeaders.Add("Accept", "*/*");

            HttpContent content = new StringContent("{\"SITE\": \"" + ConfigurationManager.AppSettings["Site"].ToString() + "\",\"RESOURCE_NO\": \"" + ConfigurationManager.AppSettings["ResourceNo"].ToString() + "\",\"DC_USER\" :\"" + username + "\",\"PASSWORD\": \"" + password + "\" }");
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            //提交参数设置
            HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["LoginUrl"].ToString(), content);
            return response;
        }

        public async Task<HttpResponseMessage> getModelList()
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
            client.DefaultRequestHeaders.Add("ContentType", "application/json");
            client.DefaultRequestHeaders.Add("ContentLength", "95");
            client.DefaultRequestHeaders.Add("Cookie", "JSESSIONID=7DCA0E7D6482817672476CD633D6F2C9");
            client.DefaultRequestHeaders.Add("Accept", "*/*");

            HttpContent content = new StringContent("{\"SITE\": \"" + ConfigurationManager.AppSettings["Site"].ToString() + "\",\"RESOURCE_NO\": \"" + ConfigurationManager.AppSettings["ResourceNo"].ToString() + "\" }");
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            //提交参数设置
            HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["GetModelUrl"].ToString(), content);
            return response;
        }
    }
}
